class Upload {
  constructor(size: number = 2048, limit: number = 5) {
    this.size = size;
    this.limit = limit;
  }
  
  protected _params: object = {};
  set params(params: object) {
    this._params = params;
  }
  get params() {
    return this._params;
  }

  public name(name: string = '') {
    this.params.name = name;
    return this;
  }

  public get() {
    return {
      value: this.value,
      accept: this.accept,
      maxNumber: this.limit,
      multiple: this.multiple,
      uploadParams: this.params,
      maxSize: this.size,
      helpText: this.help,
    };
  }

  protected _accept: Array<string> = [
    'jpg',
    'png',
    'gif',
    'txt',
    'doc',
    'docx',
    'xls',
    'xlsx',
    'ppt',
    'pptx',
    'pdf',
    'md',
    'rar',
    'tar',
    'zip',
    'bmp',
    'mp3',
    'mp4',
    'avi',
  ];
  set accept(accept: Array<string>) {
    this._accept = accept;
  }
  get accept() {
    return this._accept;
  }

  protected _multiple: Boolean = true;
  set multiple(multiple: Boolean) {
    this._multiple = multiple;
  }
  get multiple() {
    return this._multiple;
  }

  protected _limit: Number = 5;
  set limit(limit: Number) {
    this._limit = limit;
  }
  get limit() {
    return this._limit;
  }

  protected _size: number = 1024;
  set size(size: number) {
    this._size = size;
  }
  get size() {
    return parseFloat((this._size / 1024).toFixed(2));
  }

  protected _help: string = '';
  set help(help: string) {
    this._help = help;
  }
  get help() {
    if (this._help.length === 0) {
      this._help =
        '限制数量:' +
        this.limit +
        ', 允许的格式' +
        this.accept.join(' 、 ') +
        ',单个文件不超过:' +
        this._size +
        'K';
    }
    return this._help;
  }

  protected _value: Array = [];
  set value(value: Array) {
    this._value = value;
  }
  get value() {
    return this._value;
  }
}

class File extends Upload {
  // vben封装的单位是M，这里转化为K
  constructor(size: number = 2048, limit: number = 5) {
    super(size, limit);
    this.size = size;
    this.limit = limit;
    this.multiple = true;
    this.accept = ['doc', 'docx', 'txt', 'xls', 'xlsx', 'pdf', 'ppt'];
  }
}

class SimpleFile extends File {
  // vben封装的单位是M，这里转化为K
  constructor(size: number = 2048, limit: number = 5) {
    super(size, 1);
    this.limit = 1;
    this.multiple = false;
  }
}

class Video extends Upload {
  // vben封装的单位是M，这里转化为K
  constructor(size: number = 2048, limit: number = 5) {
    super(size, limit);
    this.size = size;
    this.limit = limit;
    this.multiple = true;
    this.accept = ['mp3', 'mp4', 'avi', 'wmv', 'mpg', 'mpeg', 'mov', 'rm'];
  }
}

class SimpleVideo extends Video {
  // vben封装的单位是M，这里转化为K
  constructor(size: number = 2048, limit: number = 1) {
    super(size, 1);
    this.limit = 1;
    this.multiple = false;
  }
}

class Image extends Upload {
  // vben封装的单位是M，这里转化为K
  constructor(size: number = 1024, limit: number = 5) {
    if (limit > 10) {
      limit = 10;
    }
    super(size, limit);
    this.size = size;
    this.accept = ['png', 'jpg', 'jepg', 'gif'];
    this.limit = limit;
    this.multiple = true;
  }

  /**
   * 如设置logo、icon、头像，缩略图等
   */
  setPng() {
    this.accept = ['png'];
  }
  setJpg() {
    this.accept = ['jpg'];
  }
  setPngJpg() {
    this.accept = ['png', 'jpg'];
  }
}

class SimpleImage extends Image {
  // vben封装的单位是M，这里转化为K
  constructor(size: number = 1024) {
    super(size, 10);
    this.limit = 1;
    this.multiple = false;
  }
}

export { Upload, Image, SimpleImage, File, SimpleFile, Video, SimpleVideo };
